package ro.isdc.training.ejb3.course.service.ejb;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebService;

import ro.isdc.training.ejb3.course.dao.CourseDAO;
import ro.isdc.training.ejb3.course.domain.Course;
import ro.isdc.training.ejb3.course.service.CourseService;
import ro.isdc.training.ejb3.course.service.CourseServiceRemote;
import ro.isdc.training.ejb3.course.service.domain.ReadCourseRequest;
import ro.isdc.training.ejb3.course.service.domain.ReadCourseResponse;

/**
 * Course Service Bean implementation.
 * 
 * @author Andrei Chirila
 */
@Stateless
@Remote(CourseServiceRemote.class)
/* 
 * The target namespace must be specified because otherwise it will be generated from
 * the package. If this happens, the bean webservice wsdl location will be mapped to 
 * a subpackage of the package containing the endpoint interface and it will lead
 * to inconsistent behaviour.
 */
@WebService(targetNamespace="http://service.course.ejb3.training.isdc.ro/", 
    endpointInterface="ro.isdc.training.ejb3.course.service.CourseService")
public class CourseServiceBean implements CourseService {
  
  /**
   * Course DAO injected by container.
   */
  @EJB
  private CourseDAO courseDAO;

  /**
   * {@inheritDoc}
   */
  public ReadCourseResponse readCourse(final ReadCourseRequest serviceRequest) {
    Course course = courseDAO.findCourseByIdentification(serviceRequest.getCourseId());
    
    ReadCourseResponse serviceResponse = new ReadCourseResponse();
    serviceResponse.setCourse(course);
    
    return serviceResponse;
  }

}
